package com.ling.pl.core.dao.impl;

import com.ling.pl.core.commons.constant.TableColnumDef;
import com.ling.pl.core.commons.utils.reflect.ReflectUtils;
import com.ling.pl.core.model.impl.BaseEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Created by bo.wang on 2016/8/14.
 */
//@Repository(BaseDao.BEAN_ID)
public class BaseDao extends BaseDaoSimple {

    public static final String BEAN_ID = "baseDao";

    Log log = LogFactory.getLog(BaseDao.class);

    /**
     * @param entity
     */
    public void remove(Object entity) {

        log.debug("德勤数据规范需要,如果是BaseEntity的子类删除都执行更新操作,如果需要物理删除,请通过springutils获得BaseDaoSimple的实例进行删除");
        if (entity instanceof BaseEntity) {
            BaseEntity baseEntity = (BaseEntity) get(ReflectUtils.getFullName(entity.getClass()), ((BaseEntity) entity).getId());
            baseEntity.setDeleteBy(((BaseEntity) entity).getDeleteBy());
            baseEntity.setDeleteDate(((BaseEntity) entity).getDeleteDate());
            baseEntity.setFlag(TableColnumDef.FLAG_DISABLED);
            if (baseEntity.getArchiveBaseDate() == null) {
                baseEntity.setArchiveBaseDate(((BaseEntity) entity).getArchiveBaseDate());
            }
            getSession().update(baseEntity);
        } else {
            getSession().delete(entity);
        }
    }

}
